<template>
  <div class="project-wrapper">
    <div class="section-wrapper">
      <div class="section-title">
        项目发起
      </div>
      <div class="form-border">
        <div class="section-input">
          <div class="section-label">项目名称：<span>{{projectstore.project.name}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.name !== projectstoreEdit.project.name">
          <div class="section-label">项目名称<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.name}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">项目发起人：<span>{{projectstore.project.createUserName}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">项目等级：<span>{{levelArr[projectstore.project.level]}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.level !== projectstoreEdit.project.level">
          <div class="section-label">项目等级<span style="color: red;">(修改后)</span>：<span>{{levelArr[projectstoreEdit.project.level]}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">所属部门：<span>{{projectstore.project.departmentName}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.departmentName !== projectstoreEdit.project.departmentName">
          <div class="section-label">所属部门<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.departmentName}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">项目奖金：<span>{{projectstore.project.totalBonus}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.totalBonus !== projectstoreEdit.project.totalBonus">
          <div class="section-label">项目奖金<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.totalBonus}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">项目积分：<span>{{projectstore.project.totalPoints}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.totalPoints !== projectstoreEdit.project.totalPoints">
          <div class="section-label">项目积分<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.totalPoints}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">计划开始时间：<span>{{projectstore.project.planStartTime}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.planStartTime !== projectstoreEdit.project.planStartTime">
          <div class="section-label">计划开始时间<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.planStartTime}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">计划完成时间：<span>{{projectstore.project.planEndTime}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.planEndTime !== projectstoreEdit.project.planEndTime">
          <div class="section-label">计划完成时间<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.planEndTime}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">实际开始时间：<span>{{projectstore.project.startTime}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.startTime !== projectstoreEdit.project.startTime">
          <div class="section-label">实际开始时间<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.startTime}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label">实际完成时间：<span>{{projectstore.project.endTime}}</span></div>
        </div>
        <div class="section-input" v-if="projectstore.project.endTime !== projectstoreEdit.project.endTime">
          <div class="section-label">实际完成时间<span style="color: red;">(修改后)</span>：<span>{{projectstoreEdit.project.endTime}}</span></div>
        </div>
        <div class="section-input">
          <div class="section-label-row">项目参与人员：</div>
          <el-table :data="projectstore.members" border style="width: 100%;font-weight: normal;">
            <el-table-column label="成员名称" prop="kpiItemKey" min-width="100" align="center">
              <template slot-scope="scope">
                <div style="white-space: pre-line;">{{scope.row.dingName}}<i v-if="scope.row.manager" class="el-icon-user-solid" style="margin-left:10px;"></i></div>
              </template>
            </el-table-column>
            <el-table-column label="奖励占比" min-width="100" align="center">
              <template slot-scope="scope">
                  <span>{{scope.row.percent}}</span>%
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="section-input" v-if="JSON.stringify(projectstore.members) !== JSON.stringify(projectstoreEdit.members)">
          <div class="section-label-row">项目参与人员<span style="color: red;">(修改后)</span>：</div>
          <el-table :data="projectstoreEdit.members" border style="width: 100%;font-weight: normal;">
            <el-table-column label="成员名称" prop="kpiItemKey" min-width="100" align="center">
              <template slot-scope="scope">
                <div style="white-space: pre-line;">{{scope.row.dingName}}<i v-if="scope.row.manager" class="el-icon-user-solid" style="margin-left:10px;"></i></div>
              </template>
            </el-table-column>
            <el-table-column label="奖励占比" min-width="100" align="center">
              <template slot-scope="scope">
                  <span>{{scope.row.percent}}</span>%
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="section-input">
          <div class="section-label-row">项目简介：</div>
          <div style="padding: 8px;border: 1px solid #EBEEF5;">{{projectstore.project.remark}}</div>
        </div>
        <div class="section-input" v-if="projectstore.project.remark !== projectstoreEdit.project.remark">
          <div class="section-label-row">项目简介<span style="color: red;">(修改后)</span>：</div>
          <div style="padding: 8px;border: 1px solid #EBEEF5;">{{projectstoreEdit.project.remark}}</div>
        </div>
        <div class="section-input">
          <div class="section-label-row">考核细则：</div>
          <el-table :data="projectstore.items" border style="width: 100%;font-weight: normal;">
            <el-table-column :show-overflow-tooltip="true" label="考核名称" min-width="100" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.evItemName}}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" label="考核内容描述" min-width="120" align="left" header-align="center">
              <template slot-scope="scope">
                <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
              </template>
            </el-table-column>
            <el-table-column label="分值倍数" align="center" width="70">
              <template slot-scope="scope">
                <span>{{scope.row.scoresPower}}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" label="评分人" align="center" min-width="80">
              <template slot-scope="scope">
                <span>{{scope.row.scoresGiverNames.join(',')}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="section-input" v-if="JSON.stringify(projectstore.items) !== JSON.stringify(projectstoreEdit.items)">
          <div class="section-label-row">考核细则<span style="color: red;">(修改后)</span>：</div>
          <el-table :data="projectstoreEdit.items" border style="width: 100%;font-weight: normal;">
            <el-table-column :show-overflow-tooltip="true" label="考核名称" min-width="100" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.evItemName}}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" label="考核内容描述" min-width="120" align="left" header-align="center">
              <template slot-scope="scope">
                <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
              </template>
            </el-table-column>
            <el-table-column label="分值倍数" align="center" width="70">
              <template slot-scope="scope">
                <span>{{scope.row.scoresPower}}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" label="评分人" align="center" min-width="80">
              <template slot-scope="scope">
                <span>{{scope.row.scoresGiverNames.join(',')}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div class="section-wrapper" v-if="changeLog.length > 0">
      <div class="section-title">
        项目修改记录
      </div>
      <div class="section-history">
        <el-table :data="changeLog" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData1.length > 0">
      <div class="section-title">
        立项审核记录
      </div>
      <div class="section-history">
        <el-table :data="ApprovalData1" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData2.length > 0">
      <div class="section-title">
        内容审核记录
      </div>
      <div class="section-history">
        <el-table :data="ApprovalData2" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData3.length > 0">
      <div class="section-title">
        项目开启记录
      </div>
      <div class="section-history">
        <el-table :data="ApprovalData3" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData4.length > 0">
      <div class="section-title">
        项目结束记录
      </div>
      <div class="section-history">
        <el-table :data="ApprovalData4" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="projectstore.project.status >= 5 && formType === 'check'">
      <div class="section-title">
        质量评分详情
      </div>
      <div class="section-history">
        <el-table :summary-method="getSummaries" show-summary :data="projectstore.items" border style="width: 100%;font-weight: normal;">
          <el-table-column label="考核名称" prop="evItemName" min-width="180" align="center"></el-table-column>
          <el-table-column label="考核内容描述" min-width="180" align="left" header-align="center">
            <template slot-scope="scope">
              <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
            </template>
          </el-table-column>
          <el-table-column label="分数" prop="scores" align="center" min-width="100">
            <template slot-scope="scope">
              <div style="white-space: pre-line;">{{scope.row.scores === ''? '未评分': scope.row.scores}}</div>
            </template>
            <template slot-scope="scope">
              <del v-if="scope.row.oldScores">{{scope.row.oldScores}}</del>
              <span>{{scope.row.scores}}</span>
              <span v-if="scope.row.scores && projectstore.project.status === 5" style="color:#66b1ff;cursor:pointer;" @click="openReAssessDialog(scope.row)"><i class="el-icon-edit-outline"></i></span>
              <el-tooltip v-if="scope.row.oldScores" placement="bottom" effect="light">
                <div slot="content">
                  {{scope.row.remark}}
                </div>
                <span style="color:#66b1ff;cursor:pointer;"><i class="el-icon-tickets"></i></span>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="评分详情" width="150" align="center">
            <template slot-scope="scope">
              <p v-for="item in scope.row.scoresGivers" :key="item.id">
                {{item.scoresGiverName}}({{item.scores ? item.scores + '分' : '未评分'}})
                <el-tooltip placement="bottom" effect="light">
                  <div slot="content">
                    {{item.remark}}
                  </div>
                  <span style="color:#66b1ff;cursor:pointer;"><i class="el-icon-tickets"></i></span>
                </el-tooltip>
              </p>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="projectstore.project.status > 5 && formType === 'list'">
      <div class="section-title">
        质量评分详情
      </div>
      <div class="section-history">
        <el-table :summary-method="getSummaries" show-summary :data="projectstore.items" border style="width: 100%;font-weight: normal;">
          <el-table-column label="考核名称" prop="evItemName" min-width="180" align="center"></el-table-column>
          <el-table-column label="考核内容描述" min-width="180" align="left" header-align="center">
            <template slot-scope="scope">
              <div style="white-space: pre-line;">{{scope.row.evItemContent}}</div>
            </template>
          </el-table-column>
          <el-table-column label="分数" prop="scores" align="center" min-width="80">
            <template slot-scope="scope">
              <div style="white-space: pre-line;">{{scope.row.scores === ''? '未评分': scope.row.scores}}</div>
            </template>
          </el-table-column>
          <el-table-column label="评分详情" width="150" align="center">
            <template slot-scope="scope">
              <p v-for="item in scope.row.scoresGivers" :key="item.id">
                {{item.scoresGiverName}}({{item.scores ? item.scores + '分' : '未评分'}})
                <el-tooltip placement="bottom" effect="light">
                  <div slot="content">
                    {{item.remark}}
                  </div>
                  <span style="color:#66b1ff;cursor:pointer;"><i class="el-icon-tickets"></i></span>
                </el-tooltip>
              </p>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData5.length > 0">
      <div class="section-title">
        质量评分记录
      </div>
      <div class="section-history">
        <el-table :data="ApprovalData5" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="projectstore.project.status === 6 && formType === 'check'">
      <div class="section-title">
        时间评估详情
      </div>
      <div class="section-history special">
        <el-table :data="evaluateDateShowTable" border style="width: 100%;font-weight: normal;">
          <el-table-column min-width="90" prop="name" align="center" label="名称"></el-table-column>
          <el-table-column min-width="90" align="center" label="奖金">
            <template slot-scope="scope">
              <span v-if="!scope.row.edit">{{scope.row.percentBonus}}</span>
              <el-input v-if="scope.row.edit" style="width:30px;font-size:12px;text-align:center;padding:0;" @input="valueChange" v-model="scope.row.percentBonus"></el-input> %
            </template>
          </el-table-column>
          <el-table-column min-width="140" align="center" label="积分">
            <template slot-scope="scope">
              <span v-if="!scope.row.edit">{{scope.row.percentPoints}}</span>
              <el-input v-if="scope.row.edit" style="width:30px;font-size:12px;text-align:center;padding:0;" @input="valueChange" v-model="scope.row.percentPoints"></el-input> %
            </template>
          </el-table-column>
        </el-table>
        <p>最终奖金明细</p>
        <el-table :data="finalAward" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="dingName" align="center" label="姓名" min-width="120"> </el-table-column>
          <el-table-column prop="orinBonus" align="center" label="原始项目金" min-width="120"></el-table-column>
          <el-table-column prop="projectBonusPercent" align="center" min-width="120" label="项目金得分">
            <template slot-scope="scope">
              {{scope.row.projectBonusPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalBonus" align="center" min-width="120" label="实际项目金"></el-table-column>
          <el-table-column prop="orinPoints" align="center" min-width="120" label="原始积分"></el-table-column>
          <el-table-column prop="projectPointsPercent" align="center" min-width="120" label="积分得分">
            <template slot-scope="scope">
              {{scope.row.projectPointsPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalPoints" align="center" min-width="120" label="实际积分"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="projectstore.project.status >= 7">
      <div class="section-title">
        时间评估详情
      </div>
      <div class="section-history">
        <el-table :data="evaluateDateShowTable" border style="width: 100%;font-weight: normal;">
          <el-table-column min-width="100" prop="name" align="center" label="名称"></el-table-column>
          <el-table-column min-width="100" align="center" label="奖金">
            <template slot-scope="scope">
              <span>{{scope.row.percentBonus}}</span>%
            </template>
          </el-table-column>
          <el-table-column min-width="100" align="center" label="积分">
            <template slot-scope="scope">
              <span>{{scope.row.percentPoints}}</span>%
            </template>
          </el-table-column>
        </el-table>
        <p v-if="formType === 'check'">最终奖金明细</p>
        <el-table :data="projectstore.memberSummary" v-if="formType === 'check'" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="dingName" align="center" label="姓名" min-width="120"> </el-table-column>
          <el-table-column prop="orinBonus" align="center" label="原始项目金" min-width="120"></el-table-column>
          <el-table-column prop="projectBonusPercent" align="center" min-width="120" label="项目金得分">
            <template slot-scope="scope">
              {{scope.row.projectBonusPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalBonus" align="center" min-width="120" label="实际项目金"></el-table-column>
          <el-table-column prop="orinPoints" align="center" min-width="120" label="原始积分"></el-table-column>
          <el-table-column prop="projectPointsPercent" align="center" min-width="120" label="积分得分">
            <template slot-scope="scope">
              {{scope.row.projectPointsPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalPoints" align="center" min-width="120" label="实际积分"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData6.length > 0">
      <div class="section-title">
        时间评估记录
      </div>
      <div class="section-history">
         <el-table :data="ApprovalData6" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="ApprovalData7.length > 0">
      <div class="section-title">
        终审记录
      </div>
      <div class="section-history">
         <el-table :data="ApprovalData7" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="completeTime" label="日期" min-width="150"> </el-table-column>
          <el-table-column prop="description" label="审核情况" min-width="70">
            <template slot-scope="scope">
              <span>{{scope.row.taskStatus === '1' ? '已通过': '已拒绝'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="taskOwnerName" min-width="70" label="审核人"></el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="projectRemark" min-width="120" label="审核详情"></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="section-wrapper" v-if="projectstore.project.status === 100">
      <div class="section-title">
        奖励明细
      </div>
      <div class="section-history">
        <el-table :data="projectstore.memberSummary" border style="width: 100%;font-weight: normal;">
          <el-table-column prop="dingName" align="center" fixed label="姓名" min-width="120"> </el-table-column>
          <el-table-column prop="orinBonus" align="center" label="原始项目金" min-width="120"></el-table-column>
          <el-table-column prop="projectBonusPercent" align="center" min-width="120" label="项目金得分">
            <template slot-scope="scope">
              {{scope.row.projectBonusPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalBonus" align="center" min-width="120" label="实际项目金"></el-table-column>
          <el-table-column prop="orinPoints" align="center" min-width="120" label="原始积分"></el-table-column>
          <el-table-column prop="projectPointsPercent" align="center" min-width="120" label="积分得分">
            <template slot-scope="scope">
              {{scope.row.projectPointsPercent}}%
            </template>
          </el-table-column>
          <el-table-column prop="finalPoints" align="center" min-width="120" label="实际积分"></el-table-column>
        </el-table>
      </div>
    </div>
    <div style="margin-top: 15px;" v-if="formType === 'check' && (projectstore.project.status === 5 && !projectstore.project.qualityScores)">
      <el-button type="primary" @click="notice">通知评分人</el-button>
    </div>
    <div style="margin-top: 15px;" v-if="formType === 'check' && !(projectstore.project.status === 5 && !projectstore.project.qualityScores)">
      <div v-if="projectstore.project.status === 3" style="margin-bottom: 10px;">
        <div style="margin-bottom: 10px;">项目实际开始时间</div>
        <el-date-picker type="date" :editable="false" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="audit.exData.beginTime" style="width: 100%;"></el-date-picker>
      </div>
       <div v-if="projectstore.project.status === 4" style="margin-bottom: 10px;">
        <div style="margin-bottom: 10px;">项目实际结束时间</div>
        <el-date-picker type="date" :editable="false" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="audit.exData.endTime" style="width: 100%;"></el-date-picker>
      </div>
      <div style="margin-bottom: 5px;" v-if="projectstore.project.status !== 3 && projectstore.project.status !== 4">开始审核：</div>
      <div style="margin-bottom: 5px;" v-if="projectstore.project.status !== 3 && projectstore.project.status !== 4">
        <el-radio v-model="audit.action" :label="true">通过</el-radio><el-radio v-model="audit.action" :label="false">驳回</el-radio>
      </div>
      <el-input type="textarea" :autosize="{ minRows: 4}" v-model="audit.remark"></el-input>
      <div style="margin-top: 5px;">
        <el-button type="primary" v-if="projectstore.project.status !== 6" @click="assess">确定</el-button>
        <el-button type="primary" v-if="projectstore.project.status === 6" @click="approvalDue">提交终审</el-button>
        <el-button @click="$router.go(-1)">关闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import formUtil from '@/utils/formUtil';
import dingMixin from  '@/mixins/ding'

export default {
  data() {
    return {
      finalAward: [],
      ApprovalData1: [],
      ApprovalData2: [],
      ApprovalData3: [],
      ApprovalData4: [],
      ApprovalData5: [],
      ApprovalData6: [],
      ApprovalData7: [],
      formType: '',
      levelArr: ['零级','一级','二级','三级','四级','五级'],
      projectstore: {
        items: [],
        members: [],
        logs: [],
        memberSummary: [],
        project: {
          createTime: '',
          departmentId: '',
          departmentName: '',
          endTime: '',
          id: '',
          initialor: '',
          initialorName: '',
          level: '',
          name: '',
          planEndTime: '',
          planStartTime: '',
          qualityScores: '',
          remark: '',
          startTime: '',
          totalBonus: '',
          totalPoints: ''
        }
      },
      projectstoreEdit: {
        items: [],
        members: [],
        logs: [],
        memberSummary: [],
        project: {
          createTime: '',
          departmentId: '',
          departmentName: '',
          endTime: '',
          id: '',
          initialor: '',
          initialorName: '',
          level: '',
          name: '',
          planEndTime: '',
          planStartTime: '',
          qualityScores: '',
          remark: '',
          startTime: '',
          totalBonus: '',
          totalPoints: ''
        }
      },
      evaluateDateShowTable: [],
      audit: {
        processId: '',
        taskId: '',
        action: true,
        remark: '',
        exData: {
          beginTime: '',
          endTime: ''
        }
      },
      changeLog: []
    }
  },
  mixins: [dingMixin],
  async mounted() {
    this.formType = this.$route.params.type;
    let id = this.$route.params.id;
    let taskId = this.$route.params.taskId;
    let processId = this.$route.params.processId;
    this.getData(id, taskId, processId)
  },
  methods: {
    async getData(id, taskId, processId) {
      let projectstore = await this.$httpN.postQ('pde/project/detail', {projectId: id, withLog: true});
      projectstore.items.forEach((item) => {
        item.scoresGiverNames = item.scoresGivers.map(user => user.scoresGiverName)
      })

      if(projectstore.project.editLogId && this.formType === 'check') {
        projectstore.project.status = 1;
        projectstore.members.forEach((item) => {
          item.orinBonus = '';
          item.orinPoints = '';
          item.projectId = '';
          item.id = '';
        })
        projectstore.items.forEach((item) => {
          item.projectId = '';
          item.id = '';
          item.scoresGivers.forEach((giver) => {
            giver.detailId = '';
            giver.id = '';
          })
        })
        this.projectstore = projectstore;
        this.showCheckChange = true;
        let projectstoreEdit = await this.$httpN.postQ('pde/project/editLogDetail', {editLogId: projectstore.project.editLogId});
        projectstoreEdit.items.forEach((item) => {
          item.scoresGiverNames = item.scoresGivers.map(user => user.scoresGiverName)
        })
        projectstoreEdit.members.forEach((item) => {
          item.orinBonus = '';
          item.orinPoints = '';
          item.projectId = '';
          item.id = '';
        })
        projectstoreEdit.items.forEach((item) => {
          item.projectId = '';
          item.id = '';
          item.scoresGivers.forEach((giver) => {
            giver.detailId = '';
            giver.id = '';
          })
        })

        this.projectstoreEdit = projectstoreEdit;
        this.audit.taskId = taskId;
        this.audit.processId = processId;
        this.audit.action = true;
        this.audit.remark = '';
        this.audit.exData = {
          beginTime: '',
          endTime: ''
        }
      
        return;
      }

      let history = []

      if(projectstore.project.processId) {
        let result = await this.$httpN.postB('pde/project/listAuditTask',{
          'projectId': projectstore.project.id
        })

        history = result.list;
        this.ApprovalData1 = history.filter(item => item.stepSort === '1' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData2 = history.filter(item => item.stepSort === '2' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData3 = history.filter(item => item.stepSort === '3' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData4 = history.filter(item => item.stepSort === '4' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData5 = history.filter(item => item.stepSort === '5' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData6 = history.filter(item => item.stepSort === '6' && item.taskStatus !== '0' && item.modelId === '4');
        this.ApprovalData7 = history.filter(item => item.stepSort === '7' && item.taskStatus !== '0' && item.modelId === '4');
        this.changeLog = history.filter(item => item.stepSort === '1' && item.taskStatus !== '0' && item.modelId === '5');
      }else {
        this.ApprovalData1 = [];
        this.ApprovalData2 = [];
        this.ApprovalData3 = [];
        this.ApprovalData4 = [];
        this.ApprovalData5 = [];
        this.ApprovalData6 = [];
        this.ApprovalData7 = [];
        this.changeLog = [];
      }


      if(projectstore.project.status >= 6) {
        let score = projectstore.project.finalScores ? projectstore.project.finalScores:
                        projectstore.project.overDay === '0'? projectstore.project.qualityScores : ''

        this.evaluateDateShowTable = [{
          name: '质量评分',
          percentPoints: score,
          percentBonus: score,
          edit: false
        },{
          name: '时间评分',
          percentPoints: projectstore.project.percentPoints,
          percentBonus: projectstore.project.percentBonus,
          edit: false
        },{
          name: '最终评分',
          percentPoints: score > projectstore.project.percentPoints? projectstore.project.percentPoints: score,
          percentBonus: score > projectstore.project.percentBonus? projectstore.project.percentBonus: score,
          finalScores: score,
          edit: true
        }]
      }

      if(this.formType === 'check') {
        let currentTask = history.filter((item) => item.stepSort === (projectstore.project.status + '') && item.taskStatus === '0');
        this.audit.taskId = currentTask[0].taskId;
        this.audit.processId = projectstore.project.processId;
        this.audit.action = true;
        this.audit.remark = '';
        this.audit.exData = {
          beginTime: '',
          endTime: ''
        }
      }


      if(projectstore.project.status >= 7) projectstore.memberSummary = [...projectstore.members, projectstore.memberSummary];
      this.projectstore = projectstore;
      this.projectstoreEdit = projectstore;
      if(projectstore.project.status === 6) this.getAward();
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总分';
          return;
        }else if(index === 2) {
          sums[index] = this.projectstore.project.qualityScores;
          return;
        }
      });
      return sums;
    },
    async assess() {
      if(this.projectstore.project.status === 3 && !this.audit.exData.beginTime) return formUtil.submitError('请选择项目开始时间');
        if(this.projectstore.project.status === 4 && !this.audit.exData.endTime) return formUtil.submitError('请选择项目结束时间');
      if(!await this.$httpN.postB('flow/process/audit', this.audit)) return;
      formUtil.submitSuccess('审核成功');
      this.$router.go(-1);
    },
    notice() {
      formUtil.submitConfirm('您确定通知未评分人吗?', async ()=> {
        if(!await this.$httpN.postQ('pde/project/noticeScoresGiver', {projectId: this.projectstore.project.id})) return;
        formUtil.submitSuccess('通知成功');
      })
    },
    openReAssessDialog(item) {
      this.mobileInput('请输入正整数分数(1-10)', '', async ({text}) => {
        if(isNaN(Math.floor(parseInt(text))) || Math.floor(parseInt(text))> 10 || Math.floor(parseInt(text)) <1) return formUtil.submitError('请输入正整数分数(1-10)');
        if(!await this.$httpN.postQ('pde/scores/editScores', {
          detailId: item.id,
          scores: Math.floor(parseInt(text))
        })) return;
        formUtil.submitSuccess('打分成功');
        this.getData(this.projectstore.project.id)
      })
    },
    async getAward() {
      this.finalAward = await this.$httpN.postB('pde/project/calcFinalBonus', {
        id: this.projectstore.project.id,
        finalScores: this.evaluateDateShowTable[2].finalScores,
        percentPoints: this.evaluateDateShowTable[2].percentPoints,
        percentBonus: this.evaluateDateShowTable[2].percentBonus,
      })
    },
    valueChange() {
      if(this.threadId) clearTimeout(this.threadId);
      this.threadId = setTimeout(() => {
        if(this.checkNum(this.evaluateDateShowTable[2].finalScores) && this.checkNum(this.evaluateDateShowTable[2].percentPoints) && this.checkNum(this.evaluateDateShowTable[2].percentBonus)) this.getAward();
        this.threadId = null;
      }, 600)
    },
    checkNum(num) {
      return num !== '' && !isNaN(num)
    },
    approvalDue() {
      formUtil.submitConfirm('您确定要提交终审了吗?', async ()=> {
        if(!await this.$httpN.postB('pde/project/evaluateDate', {
          id: this.projectstore.project.id,
          finalScores: this.evaluateDateShowTable[2].finalScores,
          percentPoints: this.evaluateDateShowTable[2].percentPoints,
          percentBonus: this.evaluateDateShowTable[2].percentBonus,
        })) return;
        this.assess();
      })
    },
  }
}
</script>

<style lang="scss">
  .project-wrapper{
    padding: 8px;
    padding-bottom: 30px;
    .section-wrapper{
      position: relative;
      padding-bottom: 10px;
      padding-left: 10px;
      &::before{
        content: '';
        display: block;
        width: 2px;
        height: 100%;
        position: absolute;
        left: -0;
        top: 0;
        background: #409EFF;
      }
      &::after{
        content: '';
        display: block;
        width: 12px;
        height: 12px;
        position: absolute;
        left: -5px;
        top: 0;
        background: #409EFF;
        border-radius: 50%;
        z-index:2;
      }
      .section-title{
        font-weight: bold;
        color: #409EFF;
      }
      .section-input{
        margin-bottom: 8px;
      }
      .form-border{
        padding: 8px;
        border:1px solid #EBEEF5;
        padding-bottom: 0;
        margin-top: 10px;
      }
      .section-label-row{
        margin-bottom: 5px;
      }
      .section-history{
        margin-top: 10px;
        &.special{
          .el-input--medium .el-input__inner{
            height: 20px;
            line-height: 20px;
            padding: 0;
            text-align: center;
          }
        }
      }
    }
    .list-special-tip{
      display: inline-block;
      width:70px;
      text-align: center;
    }
    .el-table--medium td, .el-table--medium th{
      padding: 0;
      font-size: 12px;
    }
  }
</style>